<?php

namespace App\Rules;

use App\Cate;
use Illuminate\Contracts\Validation\Rule;

class CheckCategoryPid implements Rule
{
   private $pid;
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct($pid)
    {
        $this->pid=$pid;
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
       
        $ids = Cate::getCateIds($this->pid);
        if(!empty($ids)){
            if(in_array($value,$ids)){
                return false;
            }
        }
        return true;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return trans('上级分类设置不正确');
    }
}